/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 16:38:50
 * @LastEditTime: 2021-08-30 16:44:10
 * @LastEditors: changqing
 * @Usage: 
 */
var { timer, interval,range,from } = require('rxjs'); 
var {distinctUntilChanged,map} = require('rxjs/operators');

//distinctUntilChanged会过滤到重复的事件值，直到事件值发生改变为止。也就是说，只要当前事件值跟上一次事件值一样，这次事件就不会发生，若目前事件值跟上一次事件值不同时，这次事件会发生


from([1, 1, 2, 3, 3, 1]).pipe(
  distinctUntilChanged()
).subscribe(data => {
  console.log(`${data}`)
});

const students = [
  { id: 1, score: 70 },
  { id: 1, score: 80 },
  { id: 2, score: 90 },
  { id: 3, score: 100 }
];
from(students).pipe(
  distinctUntilChanged(
    (studentA, studentB) => studentA.id === studentB.id
  )
)
.subscribe(student => {
  console.log(
    `${student.id} - ${student.score}`
  );
});

// 1 - 70
// 2 - 90
// 3 -100